<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <style>
        .dtree-select-show {
            z-index: 9999;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <form class="layui-form" lay-filter="myform" id="myform">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">编号前缀</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" id="name"  autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <div class="layui-btn-group">
                                <input type="reset" id="btReset" class="layui-hide" >
                                <button type="button" class="layui-btn " data-type="searchPric"><i class="layui-icon">&#xe615;</i>查询</button>
                                <button type="button" class="layui-btn " data-type="resetPric"><i class="layui-icon">&#xe669;</i>重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="layui-hide"  id="featureTable" lay-filter="featureTb"></table>
            </div>
        </div>
    </div>
</div>

<script th:inline="none"></script>
<script>
    layui.extend({
        tableSelect: '{/}layuiadmin/plugins/tableSelect' 
    });

    layui.use(['table','form','tableSelect'], function(){
        var table = layui.table,
            form = layui.form
            ,tableSelect = layui.tableSelect;

        table.render({
            elem: '#featureTable'
            ,height: (top.height-85)+'px'
            ,url: 'baseCodeNumber/getPageList' 
            ,title: '编号生成器'
            ,page: true
            ,limit:15
            ,toolbar: '#toolbarPrice'
            ,cols: [
                [ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'name', title: '名称', width: 200}
                 ,{field: 'type', title: '类型', width: 200}
                 ,{field: 'prefix', title: '前缀', width: 200}
                 ,{field: 'orgName', title: '所属公司', width: 200}
                 ,{field: 'currentNum', title: '当前序号', width: 200}
                ,{field: 'createTime', title: '登记时间', width: 200}
            ]
            ]
            ,done:function(){
            enableRowClick(table,form,'featureTable',"featureTable");
             }
        });
        //监听单元格编辑
        table.on('edit(featureTb)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            console.log('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value)
        });
        //头工具栏事件
        table.on('toolbar(featureTb)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch(obj.event){
                case 'add':
                    top.layer.open({
                        type: 2,
                        title:'增加',
                        area:['800px','600px'],
                        content:  'rooter?url=system/codenumber/add-codenumber',
                        btn:['保存','关闭'],
                        yes:function(index,layero){
                            var dataForm = top.layer.getChildFrame('form', index);
                            dataForm.find("#submitBtn").click();
                            return false
                        }
                    });
                    break;
                case 'edit':
                    var data = checkStatus.data;
                    if(data.length>1){
                     layer.msg("请勿选中多个!")
                     break;
                    }else if(data.length<1){
                        layer.msg("请选择操作数据!")
                        break;
                    }

                    top.layer.open({
                        type: 2,
                        title:'修改',
                        area:['800px','600px'],
                        content:  'rooter?url=system/codenumber/add-codenumber&id='+data[0].id,
                        btn:['保存','关闭'],
                        yes:function(index,layero){
                            var dataForm = top.layer.getChildFrame('form', index);
                            dataForm.find("#submitBtn").click();
                            return false
                        }
                    });
                    break;
                case 'delete':
                    var data = checkStatus.data;
                    if(data.length>0){
                        var values = {};
                        var ids='';
                        $.each(data,function(i,v){
                            ids+=v.id+",";
                        })
                        values['ids'] = ids;
                        layer.confirm('确定要删除当前行么?', {icon: 3, title:'提示'}, function(index){
                            axios.post('baseCodeNumber/delete',values).then(res=> {
                                if (res.data.code == 1) {
                                    layer.msg(res.msg);
                                } else {
                                    layer.close(index);
                                    table.reload('featureTable');
                                }
                            })
                        });
                    }else{
                        layer.msg("请选择操作数据!")
                    }
                    break;
            };
        });
        var $ = layui.$, active = {
            searchPric: function(){
                tbReload();
            },
            resetPric:function () {
                $("#btReset").click();
                tbReload();
            }
        };
        window.loadGrid = function(tableName){
            table.reload(tableName);
        }
        $('.layui-form .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
<script type="text/html" id="toolbarPrice">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm " lay-event="add"><i class="layui-icon layui-icon-addition"></i>增加</button>
        <button class="layui-btn layui-btn-sm " lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</button>
        <button class="layui-btn layui-btn-sm" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</button>
    </div>
</script>
</body>
</html>